﻿$(function() {
    agchpwd.init();
    Utils.textBoxsOnEnter(agchpwd._Save);
});


var agchpwd =
{
    init: function() {
        $("#btnSave").click(this._Save);
        $("#password").focus();
        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                window.parent.utility.closePopUpUrl();
            }
        });
    }
    , _Save: function() {
        var password = $("#password");
        var conpassword = $("#conpassword");
        var sn = $("#sn").val();
        targetFunction = (parent != undefined) ? parent.ErrorHelper : ErrorHelper;
        targetFunction.checkNonNull(password, m.Err0002);
        targetFunction.checkNonNull(conpassword, m.Err0007);
        if (!targetFunction.hasError) {
            targetFunction.checkIsEq(password, conpassword, m.Err0008);
            if (targetFunction.hasError) { conpassword.val(''); }
        }

        if (!targetFunction.popUpIfError()) {
            var param = { sn: sn, password: password.val() };
            var cb = function() { window.parent.utility.closePopUpUrl(); };
            var ecb = function() { $("#loginid").focus(); };
            window.parent.utility.ajaxext("AgentService/UpdateAgPwd", param, "POST", cb, ecb);
        }
    }
};